package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.server.game.commondata.secretary.SecretaryMain;
import com.motu.monstercity.server.game.userdata.UserSecretary;
import com.motu.monstercity.server.game.userdata.UserSecretaryBusiness;
import com.motu.monstercity.server.game.userdata.UserSecretaryFragment;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;
import com.motu.vertx.module.utility.toolset.Tool;

import java.util.ArrayList;
import java.util.List;

public class SecretaryUserData extends SecretaryBaseData {

    public static UserSecretary getUserSecretary(long userId, int secretaryId) {
        return (UserSecretary) EntityManager.getEntity(UserSecretary.class, userId, secretaryId);
    }

    public static List<UserSecretary> getUserSecretaries(long userId) {
        List<UserSecretary> userSecretaries = new ArrayList<>();
        List<Model> modelList = EntityManager.getEntityList(UserSecretary.class, userId);
        for (Model model : modelList) {
            UserSecretary userSecretary = (UserSecretary) model;
            userSecretaries.add(userSecretary);
        }
        return userSecretaries;
    }

    // 获取有羁绊关系的秘书列表
    public static List<UserSecretary> getUserSecrPatronList(long userId, int partnerId) {
        List<UserSecretary> result = new ArrayList<>();
        for (SecretaryMain secretaryMain : SecretaryManager.getSecretaryMainMap().values()) {
            if (Tool.isInList(secretaryMain.getSecretaryRelationList(), partnerId)) {// 有羁绊关系的秘书
                UserSecretary userSecretary = SecretaryManager.getUserSecretary(userId, secretaryMain.getSecretaryId());
                if (userSecretary != null) {
                    result.add(userSecretary);
                }
            }
        }
        return result;
    }

    public static long getUserSecretaryCount(long userId) {
        return EntityManager.getEntityCount(UserSecretary.class, userId);
    }

    public static List<UserSecretaryFragment> getUserSecretaryFragments(long userId) {
        List<UserSecretaryFragment> userSecretaries = new ArrayList<>();
        List<Model> modelList = EntityManager.getEntityList(UserSecretaryFragment.class, userId);
        for (Model model : modelList) {
            UserSecretaryFragment userSecretaryFragment = (UserSecretaryFragment) model;
            userSecretaries.add(userSecretaryFragment);
        }
        return userSecretaries;
    }
    public static UserSecretaryFragment getUserSecretaryFragment(long userId, int secretaryId) {
        return (UserSecretaryFragment) EntityManager.getEntity(UserSecretaryFragment.class, userId, secretaryId);
    }

    public static List<UserSecretaryBusiness> getUserSecretaryBusinessList(long userId, int secrId) {
        List<UserSecretaryBusiness> list = new ArrayList<>();
        String unique = SecretaryManager.getBusinessUnique(userId, secrId);
        List<Model> modelList = EntityManager.getEntityList(UserSecretaryBusiness.class, unique);
        for (Model model : modelList) {
            UserSecretaryBusiness entity = (UserSecretaryBusiness) model;
            list.add(entity);
        }
        return list;
    }

    public static UserSecretaryBusiness getUserSecretaryBusiness(long userId, int secrId, int skillId) {
        String unique = SecretaryManager.getBusinessUnique(userId, secrId);
        return (UserSecretaryBusiness) EntityManager.getEntity(UserSecretaryBusiness.class, unique, skillId);
    }

    public static long getSecretaryCount(long userId) {
        return EntityManager.getEntityCount(UserSecretary.class, userId);
    }

}
